package com.sf.marathon.soul.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sf.marathon.soul.core.base.BaseController;
import com.sf.marathon.soul.domain.ExpressGroup;
import com.sf.marathon.soul.service.ExpressGroupDetailService;
import com.sf.marathon.soul.service.ExpressGroupService;
import com.sf.marathon.soul.vo.ExpressGroupDetail;

import java.util.List;

/**
 * <p>
 * 集货拼团表 前端控制器
 * </p>
 *
 * @author mokeo
 * @since 2017-12-15
 */
@Controller
@RequestMapping("/expressGroup")
public class ExpressGroupController extends BaseController<ExpressGroup> {
    @Autowired
    private ExpressGroupService groupService;

    @Autowired
    private ExpressGroupDetailService detailService;

    @Override
    protected void init() {
        baseService = groupService;
        setMainVOClazz(null);
    }

    /**
     * 查询用户对应的拼团明细
     * @return
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public ExpressGroupDetail getDetail(@RequestParam(name = "userId") Long userId
            ,@RequestParam(name = "groupId",required = false) Long groupId) {

        List<ExpressGroup> groups = groupService.findUnfinishGroupByUserId(userId);
        if(groups != null && groups.size() >0 && groupId == null){
            groupId = groups.get(0).getId();
        }
       return detailService.findOneById(groupId);
    }

}
